package com.itheima.HomeWork;

import java.io.File;
import java.util.Scanner;

public class Demo4 {
    static int index=0;
    public static void main(String[] args) {

        Scanner scanner=new Scanner(System.in);
        System.out.println("请输入文件大致路径");
        String path= scanner.next();
        System.out.println("请输入文件名（不是文件夹）");
        String data=scanner.next();
        find(path,data);
        find("D:\\黑马线下\\temp","a.txt");
        if(index==0){
            System.out.println("没有该文件");
        }

    }

    static void find(String path,String data){
        File f=new File(path);
        File[] files = f.listFiles();

        for(File file:files){
            if(file.isDirectory()){
                find(file.getAbsolutePath(),data);
            }
            if(data.equals(file.getName())){
                index=1;
                System.out.println(file.getName()+"的文件准确路径在"+file.getAbsoluteFile());
            }
        }
    }
}
